using AndyPike.Snowflake.Core.Exceptions;
using AndyPike.Snowflake.Core.Messages;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

namespace AndyPike.Snowflake.Core.Tests.Unit.Messages
{
    [TestFixture]
    public class When_validating_credentials
    {
        [Test]
        public void Should_not_throw_an_exception_if_all_the_values_are_valid()
        {
            var credentialsMessage = new CredentialsMessage { UserName = "andypike", Password = "123456" };
            credentialsMessage.Validate();
        }

        [Test]
        [ExpectedException(typeof(InvalidUserNameException))]
        public void Should_throw_an_exception_if_user_name_is_null()
        {
            var credentialsMessage = new CredentialsMessage { UserName = null, Password = "123456" };
            credentialsMessage.Validate();
        }

        [Test]
        [ExpectedException(typeof(InvalidUserNameException))]
        public void Should_throw_an_exception_if_user_name_is_empty()
        {
            var credentialsMessage = new CredentialsMessage { UserName = "", Password = "123456" };
            credentialsMessage.Validate();
        }

        [Test]
        [ExpectedException(typeof(InvalidPasswordException))]
        public void Should_throw_an_exception_if_password_is_null()
        {
            var credentialsMessage = new CredentialsMessage { UserName = "andypike", Password = null };
            credentialsMessage.Validate();
        }

        [Test]
        [ExpectedException(typeof(InvalidPasswordException))]
        public void Should_throw_an_exception_if_password_is_empty()
        {
            var credentialsMessage = new CredentialsMessage { UserName = "andypike", Password = "" };
            credentialsMessage.Validate();
        }
    }

    [TestFixture]
    public class When_retrieving_the_password_from_the_credentials_message
    {
        [Test]
        public void Should_return_the_MD5_hash_for_a_valid_password()
        {
            var credentialsMessage = new CredentialsMessage { UserName = "andypike", Password = "andypike" };

            Assert.That(credentialsMessage.Password, Is.EqualTo("8958D00667F8878E3A06BF80F10B2D43"));
        }
    }
}